package matlap.server;

import java.sql.SQLException;
import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

import matlap.client.services.distributor.DistributorService;
import matlap.database.dao.DAOFactory;
import matlap.database.dao.DistributorDAO;
import matlap.shared.Distributor;
import matlap.shared.exceptions.MyException;

/**
 * The server side implementation of the RPC service.
 */

public class DistributorsServiceImpl extends RemoteServiceServlet implements
		DistributorService {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2667988062205567260L;
	DAOFactory df = DAOFactory.getInstance();
	DistributorDAO dd = df.getDistributorDAO();

	/**
	 * Turns back the distributors number from the distributors table.
	 * @throws SQLException 
	 * @throws ClassNotFoundException 
	 */

	@Override
	public int getDistributorsNumber() throws MyException{
		return dd.getDistributorsNumber();
	}

	/**
	 * Turns back the distributors from the people table in Distributor list.
	 */

	public List<Distributor> getDistributors() {
		return dd.getDistributors();
	}

	/**
	 * Turns back the distributors from the people table in Distributor list by
	 * adding the distributors name.
	 */

	@Override
	public List<Distributor> getDistributorsByName(String distributorName) {
		return dd.getDistributorsByName(distributorName);
	}

	/**
	 * Turns back the distributors name from the people table in Distributor
	 * list.
	 */

	@Override
	public List<Distributor> selectDistributorsName() {
		return dd.selectDistributorsName();
	}

	/**
	 * Deletes the distributor from the people table by adding the distributors
	 * username.
	 */

	public void deleteDistributors(String userName) {
		dd.deleteDistributors(userName);
	}

	/**
	 * Turns back the distributors username from the people table in String
	 * list.
	 */

	@Override
	public List<String> getUserNames() {
		return dd.getUserNames();
	}

	/**
	 * Updates the people table by adding username, first name, last name and
	 * address.
	 */

	@Override
	public void updateDistributors(String userName, String firstName,
			String lastName, String address) {

		dd.updateDistributors(userName, firstName, lastName, address);
	}

	/**
	 * Turns back the distributor from the people table by adding username in
	 * Distributor.
	 */

	@Override
	public Distributor getDistributorsByUserName(String userName) {
		return dd.getDistributorsByUserName(userName);
	}

}
